#include "Map.hh"
#include "Torus.hh"
#include "Bug.h"
#include "Square.h"
#include <iostream>
#include <iomanip>
#include <cassert>

int main(void)
{

  const unsigned X = 4;
  const unsigned Y = 9;

  Map toto(X,Y,sqrt(5),sqrt(1.),10);
  
  for(unsigned i=0; i!=X; ++i)
    {
      for(unsigned j=0; j!=Y; ++j)
        bug << ' ' << std::setw(2) << toto.to_uLocation(i,j);
      bug << std::endl;
    }
  bug << std::endl;
  bug << "direction map" << std::endl;

  for(unsigned i=0; i!=X; ++i)
    {
      for(unsigned j=0; j!=Y; ++j)
        bug << ' ' << std::setw(2) << toto.to_uLocation(i,j);
      bug << std::endl;
    }
  bug << std::endl;
  
  for(unsigned d=0; d!=Torus::TDIRECTIONS+1; ++d)
    {
      bug << "Direction: " << d << std::endl;
      for(unsigned i=0; i!=X; ++i)
	{
	  for(unsigned j=0; j!=Y; ++j)
	    bug << ' ' << std::setw(2) 
                << toto.to_uLocation(i,j) << "->" << std::setw(2) << toto.slow_getLocation(toto.to_uLocation(i,j),d);
	  bug << std::endl;
	}
      bug << std::endl;
    }

  for(unsigned r=0; r!=X; ++r)
    {
      for(unsigned c=0; c!=Y; ++c)
         {
             assert(toto.getLocation(toto.to_uLocation(r,c), 0) == toto.to_uLocation((r-1+X)%X,c));
             assert(toto.getLocation(toto.to_uLocation(r,c), 1) == toto.to_uLocation(r,(c+1)%Y));
             assert(toto.getLocation(toto.to_uLocation(r,c), 2) == toto.to_uLocation((r+1)%X,c));
             assert(toto.getLocation(toto.to_uLocation(r,c), 3) == toto.to_uLocation(r,(c-1+Y)%Y));
             assert(toto.getLocation(toto.to_uLocation(r,c), 4) == toto.to_uLocation(r,c));
         }
    }


  bug << "attack reach map" << std::endl;

  for(unsigned i=0; i!=X; ++i)
    {
      for(unsigned j=0; j!=Y; ++j)
        bug << ' ' << std::setw(2) << toto.to_uLocation(i,j);
      bug << std::endl;
    }
  bug << std::endl;


  for(unsigned r=0; r!=X; ++r)
    {
      for(unsigned c=0; c!=Y; ++c)
	{
          bug << '(' << std::setw(2) << toto.to_uLocation(r,c) << "):" ;
          for(unsigned i=0; i!=toto.attack_reach_map[toto.to_uLocation(r,c)].size(); ++i)
            bug << ' ' << toto.attack_reach_map[toto.to_uLocation(r,c)][i];
	  bug << std::endl;
	}
      bug << std::endl;
      bug << std::endl;
    }
  bug << std::endl;


  return 0;
}
